﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kristall.Managers;

namespace Kristall.Screens
{
    public class MainMenuScreen : MenuScreen
    {
        MessageScreen confirmExit = new MessageScreen("Are you sure you want to exit the game?", Buttons.YesNo);
        public MainMenuScreen() : base("Kristall")
        {
            MenuEntry start = new MenuEntry("Start Game");
            MenuEntry levelEditor = new MenuEntry("Level Editor");
            MenuEntry options = new MenuEntry("Options");
            MenuEntry exit = new MenuEntry("Exit");
            start.OnSelect += new EventHandler(start_OnSelect);
            exit.OnSelect += new EventHandler(exit_OnSelect);
            levelEditor.OnSelect += new EventHandler(levelEditor_OnSelect);
            options.OnSelect += new EventHandler(options_OnSelect);
            MenuEntries.Add(start);
            MenuEntries.Add(levelEditor);
            MenuEntries.Add(options);
            MenuEntries.Add(exit);

            confirmExit.OnYes += new EventHandler(msg_OnAccept);
        }

        void options_OnSelect(object sender, EventArgs e)
        {
            ScreenManager.AddScreen(new OptionsScreen());
        }

        public override void LoadContent()
        {
            base.LoadContent();

            confirmExit.ScreenManager = ScreenManager;
            confirmExit.LoadContent();
        }

        public override void OnCancel(object sender, EventArgs e)
        {
            ScreenManager.AddScreen(confirmExit);
        }

        void msg_OnAccept(object sender, EventArgs e)
        {
            ScreenManager.Game.Exit();
        }

        LevelEditor lvlEditor;

        void levelEditor_OnSelect(object sender, EventArgs e)
        {
            lvlEditor = new LevelEditor(ScreenManager.Game);
            LoadingScreen ls = new LoadingScreen(lvlEditor);
            ls.OnLoadingCompleted += new EventHandler(ls_OnLoadingCompleted);
            ScreenManager.AddScreen(ls);
        }

        void ls_OnLoadingCompleted(object sender, EventArgs e)
        {
            lvlEditor.ToolPalette.Show();
        }

        void exit_OnSelect(object sender, EventArgs e)
        {
            OnCancel(this, null);
        }

        void start_OnSelect(object sender, EventArgs e)
        {
            GameplayScreen gps = new GameplayScreen(GameplayScreen.FirstLevel);
            ScreenManager.AddScreen(new LoadingScreen(gps));
        }


    }
}
